<!-- 知识库操作配置页面 -->
<template>
  <div>
    <el-form label-width="140px" size="small">
      <el-row>
        <el-col :span="18">
          <el-form-item label="节点名称">
            <el-input disabled v-model="nodeName"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="18">
          <el-form-item label="节点类型">
            <el-radio-group disabled v-model="nodeType">
              <el-radio label="category" name="category">分类节点</el-radio>
              <el-radio label="feature" name="feature">知识对象</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="18">
          <el-form-item label="数据新增模式">
            <el-radio-group v-model="settingValue.addMode">
              <el-radio v-for="item in tableDataAddMode" :key="item.code" :label="item.code" :name="item.code">{{
                item.label }}</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="18">
          <el-form-item label="数据删除模式">
            <el-radio-group v-model="settingValue.deleteMode">
              <el-radio v-for="item in tableDataDeleteMode" :key="item.code" :label="item.code" :name="item.code">{{
                item.label }}</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="18">
          <el-form-item label="记录操作日志">
            <el-switch v-model="settingValue.recordOperLog" active-color="#13ce66" active-value="record" inactive-value="not_record">
            </el-switch>
          </el-form-item>
        </el-col>
      </el-row>

    </el-form>
  </div>
</template>
<script>
import { $LibrarySettingApi } from '@/network/library/LibrarySettingApi';
export default {
  name: 'LibrarySettingForm',
  props: {
    nodeId: {
      type: String,
      default: ""
    },
    nodeName: {
      type: String,
      default: ""
    },
    nodeType: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      settingId: "",
      // 接口取到的配置对象
      settingInfo: {},
      librarySettings: null,

      // 页面 v-model 绑定对象
      settingValue: {
        addMode: "",
        deleteMode: "",
        recordOperLog: "",
      }
    }
  },

  computed: {
    tableDataAddMode() {
      if (this.settingInfo.TableDataAddMode) {
        return this.settingInfo.TableDataAddMode['settingNodeList'];
      }
    },

    tableDataDeleteMode() {
      if (this.settingInfo.TableDataDeleteMode) {
        return this.settingInfo.TableDataDeleteMode['settingNodeList'];
      }
    },
  },

  methods: {
    async loadLibrarySettings() {
      const res = await $LibrarySettingApi.getByNodeId({ nodeId: this.nodeId });
      this.settingInfo = res.data.settingsMap;
      this.settingId = res.data.settingId;
      this.settingValue.addMode = this.settingInfo.TableDataAddMode.value;
      this.settingValue.deleteMode = this.settingInfo.TableDataDeleteMode.value;
      this.settingValue.recordOperLog = this.settingInfo.RecordOperLog.value;
    },

    // 获取提交数据
    takeFormData() {
      this.settingInfo.TableDataAddMode.value = this.settingValue.addMode;
      this.settingInfo.TableDataDeleteMode.value = this.settingValue.deleteMode;
      this.settingInfo.RecordOperLog.value = this.settingValue.recordOperLog;
      return {
        settingId: this.settingId,
        settingInfo: this.settingInfo
      };
    },
  },

  beforeMount() {
    this.loadLibrarySettings();
  },

}
</script>
<style>

</style>
